home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Pascal / Applications / NIH Image 1.59 / 1.59 Source / Init.p < prev    next >
Encoding:
Text File  |  1995-10-26  |  49.7 KB  |  1,688 lines  |  [TEXT/PJMM]

  1. unit Init;
  2.  
  3. interface
  4.  
  5.  
  6.     uses
  7.         Memory, QuickDraw, Packages, Menus, Events, Fonts, Scrap, ToolUtils, Resources, Errors, Palettes, Slots, SegLoad, Processes, Folders, globals, Utilities, Graphics, Lut, Strings;
  8.  
  9.     procedure Init;
  10.     procedure AllocateBuffers;
  11.     procedure AllocateArrays;
  12.     procedure SetupMenus;
  13.     procedure GetPreferences(f: integer);
  14.     procedure GetSettings;
  15.     procedure FindPlugIns;
  16.  
  17.  
  18.  
  19. implementation
  20.  
  21.  
  22.     procedure MakeCursors;
  23.         var
  24.             TempCurH: CursHandle;
  25.             i, id: integer;
  26.     begin
  27.         TempCurH := GetCursor(PickerCursorID);
  28.         if TempCurH <> nil then
  29.             begin
  30.                 PickerCursor := TempCurH^^;
  31.                 ToolCursor[PickerTool] := PickerCursor;
  32.                 ReleaseResource(handle(TempCurH));
  33.             end;
  34.  
  35.         TempCurH := GetCursor(CrossCursorPlusID);
  36.         if TempCurH <> nil then
  37.             begin
  38.                 CrossPlusCursor := TempCurH^^;
  39.                 ReleaseResource(handle(TempCurH));
  40.             end;
  41.  
  42.         TempCurH := GetCursor(CrossCursorMinusID);
  43.         if TempCurH <> nil then
  44.             begin
  45.                 CrossMinusCursor := TempCurH^^;
  46.                 ReleaseResource(handle(TempCurH));
  47.             end;
  48.  
  49.         TempCurH := GetCursor(WandPlusCursorID);
  50.         if TempCurH <> nil then
  51.             begin
  52.                 WandPlusCursor := TempCurH^^;
  53.                 ReleaseResource(handle(TempCurH));
  54.             end;
  55.  
  56.         TempCurH := GetCursor(WandMinusCursorID);
  57.         if TempCurH <> nil then
  58.             begin
  59.                 WandMinusCursor := TempCurH^^;
  60.                 ReleaseResource(handle(TempCurH));
  61.             end;
  62.  
  63.         TempCurH := GetCursor(CrossCursorID);
  64.         if TempCurH <> nil then
  65.             begin
  66.                 ToolCursor[SelectionTool] := TempCurH^^;
  67.                 ToolCursor[FreehandTool] := TempCurH^^;
  68.                 ToolCursor[PolygonTool] := TempCurH^^;
  69.                 ToolCursor[ruler] := TempCurH^^;
  70.                 ToolCursor[PlotTool] := TempCurH^^;
  71.                 ToolCursor[OvalSelectionTool] := TempCurH^^;
  72.                 ToolCursor[LineTool] := TempCurH^^;
  73.                 ToolCursor[AngleTool] := TempCurH^^;
  74.                 ToolCursor[CrossHairTool] := TempCurH^^;
  75.                 ToolCursor[LUTTool] := TempCurH^^;
  76.                 ReleaseResource(handle(TempCurH));
  77.             end;
  78.  
  79.         TempCurH := GetCursor(LUTCursorID);
  80.         if TempCurH <> nil then
  81.             begin
  82.                 LUTCursor := TempCurH^^;
  83.                 ReleaseResource(handle(TempCurH));
  84.             end;
  85.  
  86.         TempCurH := GetCursor(gmCursorID);
  87.         if TempCurH <> nil then
  88.             begin
  89.                 gmCursor := TempCurH^^;
  90.                 ReleaseResource(handle(TempCurH));
  91.             end;
  92.  
  93.         TempCurH := GetCursor(GrabberCursorID);
  94.         if TempCurH <> nil then
  95.             begin
  96.                 ToolCursor[Grabber] := TempCurH^^;
  97.                 ReleaseResource(handle(TempCurH));
  98.             end;
  99.  
  100.         TempCurH := GetCursor(PencilCursorID);
  101.         if TempCurH <> nil then
  102.             begin
  103.                 ToolCursor[Pencil] := TempCurH^^;
  104.                 ReleaseResource(handle(TempCurH));
  105.             end;
  106.  
  107.         TempCurH := GetCursor(GlassCursorPlusID);
  108.         if TempCurH <> nil then
  109.             begin
  110.                 ToolCursor[MagnifyingGlass] := TempCurH^^;
  111.                 ReleaseResource(handle(TempCurH));
  112.             end;
  113.  
  114.         TempCurH := GetCursor(GlassCursorMinusID);
  115.         if TempCurH <> nil then
  116.             begin
  117.                 GlassMinusCursor := TempCurH^^;
  118.                 ReleaseResource(handle(TempCurH));
  119.             end;
  120.  
  121.         TempCurH := GetCursor(BucketCursorID);
  122.         if TempCurH <> nil then
  123.             begin
  124.                 ToolCursor[PaintBucket] := TempCurH^^;
  125.                 ReleaseResource(handle(TempCurH));
  126.             end;
  127.  
  128.         TempCurH := GetCursor(WandCursorID);
  129.         if TempCurH <> allocate the ', BufSizeStr, 'K Undo buffer. Many operations may fail or be Undoable.'));
  130.                 UndoBufSize := 0;
  131.             end;
  132.         if BigBuf <> nil then
  133.             ClipBuf := ptr(ord4(BigBuf) + BufferSize)
  134.         else
  135.             begin
  136.                 if FreeMem > (BufferSize + 300000) then
  137.                     ClipBuf := NewPtr(BufferSize)
  138.                 else
  139.                     ClipBuf := nil;
  140.             end;
  141.         UndoInfoRec := NoInfo^;
  142.         UndoInfo := @UndoInfoRec;
  143.         if UndoBuf <> nil then
  144.             with UndoInfo^ do
  145.                 begin
  146.                     roiRgn := NewRgn;
  147.                     PicBaseAddr := UndoBuf;
  148.                     osPort := CGrafPtr(NewPtr(SizeOf(CGrafPort)));
  149.                     OpenCPort(osPort);
  150.                     osPort^.portPixMap^^.BaseAddr := PicBaseAddr;
  151.                     SetPalette(WindowPtr(osPort), ExplicitPalette, false);
  152.                 end;
  153.         if ClipBuf <> nil then
  154.             begin
  155.                 ClipBufSize := BufferSize;
  156.                 ClipBufInfoRec := NoInfo^;
  157.                 ClipBufInfo := @ClipBufInfoRec;
  158.                 with ClipBufInfo^ do
  159.                     begin
  160.                         roiRgn := NewRgn;
  161.                         PicBaseAddr := ClipBuf;
  162.                         osPort := CGrafPtr(NewPtr(SizeOf(CGrafPort)));
  163.                         OpenCPort(osPort);
  164.                         osPort^.portPixMap^^.BaseAddr := PicBaseAddr;
  165.                         BytesPerRow := 0;
  166.                         SetPalette(WindowPtr(osPort), ExplicitPalette, false);
  167.                     end;
  168.             end
  169.         else
  170.             begin
  171.                 PutError(concat('There is not enough memory available to allocate the ', BufSizeStr, 'K Clipboard Buffer. Many operations, including Copy and Paste, may fail.'));
  172.                 ClipBufSize := 0;
  173.             end;
  174.         SetPort(tPort);
  175.         SetGDevice(SaveGDevice);
  176.     end;
  177.  
  178.  
  179.     procedure AllocateArrays;
  180.         var
  181.             nItems: LongInt;
  182.             i: integer;
  183.  
  184.         procedure Abort;
  185.         begin
  186.             PutError('Not enough memory available to allocate arrays.');
  187.             ExitToShell;
  188.         end;
  189.  
  190.     begin
  191.         PlotData := rLinePtr(NewPtr(SizeOf(rLineType)));
  192.         if PlotData = nil then
  193.             abort;
  194.         nItems := maxCoordinates;
  195.         xCoordinates := xCoordinatesPtr(NewPtr(nItems * SizeOf(integer)));
  196.         if xCoordinates = nil then
  197.             abort;
  198.         yCoordinates := yCoordinatesPtr(NewPtr(nItems * SizeOf(integer)));
  199.         if yCoordinates = nil then
  200.             abort;
  201.         nItems := MaxMeasurements + 1;
  202.         mean := meanPtr(NewPtr(nItems * SizeOf(real)));
  203.         if mean = nil then
  204.             abort;
  205.         sd := sdPtr(NewPtr(nItems * SizeOf(real)));
  206.         if sd = nil then
  207.             abort;
  208.         PixelCount := PixelCountPtr(NewPtr(nItems * SizeOf(LongInt)));
  209.         if PixelCount = nil then
  210.             abort;
  211.         mArea := AreaPtr(NewPtr(nItems * SizeOf(real)));
  212.         if mArea = nil then
  213.             abort;
  214.         mode := modePtr(NewPtr(nItems * SizeOf(real)));
  215.         if mode = nil then
  216.             abort;
  217.         IntegratedDensity := IntegratedDensityPtr(NewPtr(nItems * SizeOf(real)));
  218.         if IntegratedDensity = nil then
  219.             abort;
  220.         idBackground := idBackgroundPtr(NewPtr(nItems * SizeOf(real)));
  221.         if idBackground = nil then
  222.             abort;
  223.         xcenter := xcenterPtr(NewPtr(nItems * SizeOf(real)));
  224.         if xcenter = nil then
  225.             abort;
  226.         ycenter := ycenterPtr(NewPtr(nItems * SizeOf(real)));
  227.         if ycenter = nil then
  228.             abort;
  229.         MajorAxis := MajorAxisPtr(NewPtr(nItems * SizeOf(real)));
  230.         if MajorAxis = nil then
  231.             abort;
  232.         MinorAxis := MinorAxisPtr(NewPtr(nItems * SizeOf(real)));
  233.         if MinorAxis = nil then
  234.             abort;
  235.         orientation := orientationPtr(NewPtr(nItems * SizeOf(real)));
  236.         if orientation = nil then
  237.             abort;
  238.         mMin := MinPtr(NewPtr(nItems * SizeOf(real)));
  239.         if mMin = nil then
  240.             abort;
  241.         mMax := MaxPtr(NewPtr(nItems * SizeOf(real)));
  242.         if mMax = nil then
  243.             abort;
  244.         plength := plengthPtr(NewPtr(nItems * SizeOf(real)));
  245.         if plength = nil then
  246.             abort;
  247.         User1 := User1Ptr(NewPtr(nItems * SizeOf(real)));
  248.         if User1 = nil then
  249.             abort;
  250.         for i := 0 to MaxMeasurements do
  251.             User1^[i] := 0.0;
  252.         User2 := User2Ptr(NewPtr(nItems * SizeOf(real)));
  253.         if User2 = nil then
  254.             abort;
  255.         for i := 0 to MaxMeasurements do
  256.             User2^[i] := 0.0;
  257.         ClearResults(0);
  258.         if FreeMem < MinFree then
  259.             Abort;
  260.     end;
  261.  
  262.  
  263.     procedure GetKernelsWorkingDir (var settings: SettingsType);
  264.         var
  265.             wdRefNum: integer;
  266.             err: OSErr;
  267.     begin
  268.         with settings do
  269.             if sKernelsVRefNum <> 0 then
  270.                 begin
  271.                     err := OpenWD(sKernelsVRefNum, sKernelsDirID, 0, wdRefNum);
  272.                     if err = NoErr then
  273.                         KernelsRefNum := wdRefNum;
  274.           {ShowMessage(concat('KernelsRefNum=', long2str(KernelsRefNum), crStr, 'vRefNum=', long2str(sKernelsVRefNum), crStr, 'DirID=', long2str(sKernelsDirID)));}
  275.                 end;
  276.     end;
  277.  
  278.  
  279.     procedure GetDefaultWorkingDir (var settings: SettingsType);
  280.         var
  281.             wdRefNum: integer;
  282.             err: OSErr;
  283.     begin
  284.         with settings do
  285.             if sDefaultVRefNum <> 0 then
  286.                 begin
  287.                     err := OpenWD(sDefaultVRefNum, sDefaultDirID, 0, wdRefNum);
  288.                     if err = NoErr then
  289.                         DefaultRefNum := wdRefNum;
  290.                 end;
  291.     end;
  292.  
  293.  
  294. procedure GetPreferences(f: integer);
  295.         var
  296.             err: OSErr;
  297.             ByteCount: LongInt;
  298.             ok: boolean;
  299.             size: LongInt;
  300.             settings: SettingsType;
  301.             i: integer;
  302.     begin
  303.         err := GetEof(f, ByteCount);
  304.         if ByteCount > SizeOf(settings) then
  305.             ByteCount := SizeOf(settings);
  306.         err := fsRead(f, ByteCount, @settings);
  307.         if err <> NoErr then
  308.             exit(GetPreferences);
  309.         err := fsClose(f);
  310.         with settings, info^ do
  311.             begin
  312.                 if sID <> 'IMAG' then
  313.                     begin
  314.                         PutError('The "Image Prefs" file in the System folder is corrupted. Please delete it and try again.');
  315.                         exitToShell;
  316.                     end;
  317.                 if (ForegroundIndex <> sForegroundIndex) or (BackgroundIndex <> sBackgroundIndex) then
  318.                     begin
  319.                         SetForegroundColor(sForegroundIndex);
  320.                         SetBackgroundColor(sBackgroundIndex);
  321.                     end;
  322.                 BrushHeight := sBrushHeight;
  323.                 BrushWidth := sBrushWidth;
  324.                 SprayCanDiameter := sSprayCanDiameter;
  325.                 SprayCanRadius := SprayCanDiameter div 2;
  326.                 SprayCanRadius2 := SprayCanRadius * SprayCanRadius;
  327.                 CurrentFontID := sCurrentFontID;
  328.                 CurrentStyle := SCurrentStyle;
  329.                 CurrentSize := sCurrentSize;
  330.                 TextJust := sTextJust;
  331.                 TextBack := sTextBack;
  332.                 nExtraColors := sNExtraColors;
  333.                 ExtraColors := sExtraColors;
  334.                 InvertVideo := sInvertVideo;
  335.                 Measurements := sMeasurements;
  336.                 InvertPlots := sInvertPlots;
  337.                 AutoScalePlots := sAutoScalePlots;
  338.                 LinePlot := sLinePlot;
  339.                 DrawPlotLabels := sDrawPlotLabels;
  340.                 FixedSizePlot := sFixedSizePlot;
  341.                 ProfilePlotWidth := sProfilePlotWidth;
  342.                 ProfilePlotHeight := sProfilePlotHeight;
  343.                 FramesToAverage := sFramesToAverage;
  344.                 NewPicWidth := sNewPicWidth;
  345.                 NewPicHeight := sNewPicHeight;
  346.                 BufferSize := sBufferSize;
  347.                 MaxScionWidth := sMaxScionWidth;
  348.                 ThresholdToForeground := sThresholdToForeground;
  349.                 NonThresholdToBackground := sNonThresholdToBackground;
  350.                 VideoChannel := sVideoChannel;
  351.                 WhatToImport := sWhatToImport;
  352.                 ImportCustomWidth := sImportCustomWidth;
  353.                 ImportCustomHeight := sImportCustomHeight;
  354.                 ImportCustomOffset := sImportCustomOffset;
  355.         {WandAutoMeasure := sWandAutoMeasure;}
  356.                 WandAdjustAreas := sWandAdjustAreas;
  357.                 BinaryIterations := sBinaryIterations;
  358.                 ScaleArithmetic := sScaleArithmetic;
  359.                 InvertPixelValues := sInvertPixelValues;
  360.                 InvertYCoordinates := sInvertYCoordinates;
  361.                 FieldWidth := sFieldWidth;
  362.                 precision := sPrecision;
  363.                 MinParticleSize := sMinParticleSize;
  364.                 MaxParticleSize := sMaxParticleSize;
  365.                 IgnoreParticlesTouchingEdge := sIgnoreParticlesTouchingEdge;
  366.                 LabelParticles := sLabelParticles;
  367.                 OutlineParticles := sOutlineParticles;
  368.          {IncludeHoles := sIncludeHoles;}
  369.                 OscillatingMovies := sOscillatingMovies;
  370.          {DriverHalftoning := sDriverHalftoning;}
  371.                 MaxMeasurements := sMaxMeasurements;
  372.                 ImportCustomDepth := sImportCustomDepth;
  373.                 ImportSwapBytes := sImportSwapBytes;
  374.                 ImportCalibrate := sImportCalibrate;
  375.                 ImportAutoscale := sImportAutoscale;
  376.                 ShowHeadings := sShowHeadings;
  377.                 if sVersion >= 140 then
  378.                     begin
  379.                         ProfilePlotMin := sProfilePlotMin;
  380.                         ProfilePlotMax := sProfilePlotMax;
  381.                         ImportMin := sImportMin;
  382.                         ImportMax := sImportMax;
  383.                         HighlightSaturatedPixels := sHighlightPixels;
  384.                     end;
  385.                 if sVersion >= 141 then
  386.                     begin
  387.                         BallRadius := sBallRadius;
  388.                         FasterBackgroundSubtraction := sFasterBackgroundSubtraction;
  389.                         ScaleConvolutions := sScaleConvolutions;
  390.                     end;
  391.                 if sVersion >= 142 then
  392.                     begin
  393.                         BinaryCount := sBinaryCount;
  394.                         BinaryThreshold := BinaryCount * 255;
  395.                         if (sLUTMode = Pseudocolor) and (sColorTable <> CustomTable) and (sColorTable <= Spectrum) then
  396.                             begin
  397.                                 SwitchColorTables(GetColorTableItem(sColorTable), false);
  398.                                 ColorStart := sColorStart;
  399.                                 ColorEnd := sColorEnd;
  400.                                 LutMode := Pseudocolor;
  401.                                 if sInvertedTable then
  402.                                     InvertPalette;
  403.                                 UpdateLut;
  404.                             end;
  405.                     end;
  406.                 if sVersion >= 144 then
  407.                     begin
  408.                         HalftoneFrequency := sHalftoneFrequency;
  409.                         HalftoneAngle := sHalftoneAngle;
  410.                         HalftoneDotFunction := sHalftoneDotFunction;
  411.                     end;
  412.                 if sVersion >= 146 then
  413.                     begin
  414.                         DacLow := sDacLow;
  415.                         DacHigh := sDacHigh;
  416.                     end;
  417.                 if (sVersion >= 147) and ((FrameGrabber = ScionLG3) or (FrameGrabber = ScionAG5) or (FrameGrabber = ScionVG5f)) then
  418.                     SyncMode := sSyncMode;
  419.                 if sVersion >= 149 then
  420.                     begin
  421.                         SwitchLUTOnSuspend := sSwitchLUTOnSuspend;
  422.                         VideoRateAveraging := sVideoRateAveraging;
  423.                     end;
  424.                 if sVersion >= 150 then
  425.                     begin
  426.                         ImportInvert := sImportInvert;
  427.                     end;
  428.                 if sVersion >= 152 then
  429.                     begin
  430.                         if sTextCreator[1] <> chr(0) then
  431.                             TextCreator := sTextCreator;
  432.                     end;
  433.                 if sVersion >= 156 then
  434.                     begin
  435.                         if sMathSubGain <> 0.0 then begin
  436.                             MathSubGain:=sMathSubGain;
  437.                             MathSubOffset:=sMathSubOffset;
  438.                             MathGain:=MathSubGain;
  439.                             MathOffset:=MathSubOffset;
  440.                         end;
  441.                     end;
  442.                 GetKernelsWorkingDir(settings);
  443.                 GetDefaultWorkingDir(settings);
  444.                 UpdateFitEllipse;
  445.             end; {with settings, info^}
  446.         case info^.LUTMode of
  447.             PseudoColor, ColorLut, CustomGrayscale: 
  448.                 UpdateLUT;
  449.             OldAppleDefault: 
  450.                 ok := LoadCLUTResource(AppleDefaultCLUT);
  451.             otherwise
  452.         end;
  453.         if nExtraColors > 0 then
  454.             RedrawLUTWindow;
  455.         if InvertPixelValues then
  456.             InvertGrayLevels;
  457.     end;
  458.  
  459.  
  460. procedure GetSettings;
  461.         var
  462.             err: OSErr;
  463.             f: integer;
  464.             ByteCount: LongInt;
  465.             ok: boolean;
  466.             size: LongInt;
  467.             settings: SettingsType;
  468.             i: integer;
  469.             PrefsFound:boolean;
  470.             PrefsVRef: integer;
  471.             PrefsDirID: LongInt;
  472.             PrefsSpec: FSSpec;
  473.     begin
  474.         PrefsFound:=false;
  475.         if System7 then begin
  476.             {Look in the Preferences folder}
  477.             err:=FindFolder(kOnSystemDisk, kPreferencesFolderType,
  478.                         kDontCreateFolder, PrefsVRef, PrefsDirID);
  479.             if err=noErr then
  480.                 err:=FSMakeFSSpec(PrefsVRef, PrefsDirID, PrefsName, PrefsSpec);
  481.             if err=noErr then
  482.                 err:=FSpOpenDF(PrefsSpec, fsCurPerm, f);
  483.             if err=noErr then
  484.                 PrefsFound:=true;
  485.         end;
  486.         if not PrefsFound then begin
  487.             {Look in the System folder}
  488.             err := fsopen(PrefsName, SystemRefNum, f);
  489.             if err <> NoErr then
  490.                 exit(GetSettings);
  491.         end;
  492.         GetPreferences(f);
  493.     end;
  494.  
  495.  
  496.     procedure MakePatterns;
  497. {Creates the patterns used to create the "marching ants". Thanks to}
  498. {Seth Snyder on CompuServe for the example.}
  499.         var
  500.             i, j: Integer;
  501.     begin
  502.         j := 0;
  503.         for i := 0 to 7 do
  504.             begin
  505.                 AntPattern[i].pat[(j + 0) mod 8] := $1F;
  506.                 AntPattern[i].pat[(j + 1) mod 8] := $3E;
  507.                 AntPattern[i].pat[(j + 2) mod 8] := $7C;
  508.                 AntPattern[i].pat[(j + 3) mod 8] := $F8;
  509.                 AntPattern[i].pat[(j + 4) mod 8] := $F1;
  510.                 AntPattern[i].pat[(j + 5) mod 8] := $E3;
  511.                 AntPattern[i].pat[(j + 6) mod 8] := $C7;
  512.                 AntPattern[i].pat[(j + 7) mod 8] := $8F;
  513.                 j := j + 1;
  514.             end;
  515.         PatIndex := 0;
  516.     end;
  517.  
  518.  
  519.     procedure InitExtraColors;
  520.         var
  521.             i, j, ctop, cbottom, entry: integer;
  522.             tRect: rect;
  523.     begin
  524.         with ExtraColors[1] do
  525.             begin
  526.                 red := -1;
  527.                 green := 0;
  528.                 blue := 0;
  529.             end;
  530.         with ExtraColors[2] do
  531.             begin
  532.                 red := 0;
  533.                 green := -1;
  534.                 blue := 0;
  535.             end;
  536.         with ExtraColors[3] do
  537.             begin
  538.                 red := 0;
  539.                 green := 0;
  540.                 blue := -1;
  541.             end;
  542.         with ExtraColors[4] do
  543.             begin
  544.                 red := -1;
  545.                 green := -1;
  546.                 blue := 0;
  547.             end;
  548.         with ExtraColors[5] do
  549.             begin
  550.                 red := 0;
  551.                 green := -1;
  552.                 blue := -1;
  553.             end;
  554.         with ExtraColors[6] do
  555.             begin
  556.                 red := -1;
  557.                 green := 0;
  558.                 blue := -1;
  559.             end;
  560.         ctop := 256;
  561.         cbottom := ctop + ExtraColorsHeight;
  562.         for i := 1 to MaxExtraPlus2 do
  563.             begin
  564.                 SetRect(tRect, 0, ctop, cwidth, cbottom);
  565.                 ExtraColorsRect[i] := tRect;
  566.                 ctop := ctop + ExtraColorsHeight;
  567.                 cbottom := cbottom + ExtraColorsHeight;
  568.             end;
  569.         ExtraColorsEntry[1] := WhiteIndex;
  570.         ExtraColorsEntry[2] := BlackIndex;
  571.         entry := FirstExtraColorsEntry;
  572.         j := 3;
  573.         for i := 1 to MaxExtraColors do
  574.             begin
  575.                 ExtraColorsEntry[j] := entry;
  576.                 j := j + 1;
  577.                 Entry := Entry + 1;
  578.             end;
  579.     end;
  580.  
  581.  
  582.     function GetSlotBase (id: integer): LongInt;
  583.   {Returns the slot base address of the NuBus card with the specified id. The address}
  584.   {returned is in the form $Fss00000, which is valid in both 24 and 32-bit modes.}
  585.   {Returns 0 if a card with the given id is not found.}
  586.         type
  587.             SPRAMRecord = packed record
  588.                     BoardId: integer;
  589.                     VenderUse: packed array[1..6] of SignedByte;
  590.                 end;
  591.         var
  592.             SlotBlock: SpBlock;
  593.             sparm: SPRAMRecord;
  594.             SparmAddr: LongInt;
  595.             i: integer;
  596.             err: OSErr;
  597.     begin
  598.         with SlotBlock do
  599.             begin
  600.                 SparmAddr := LongInt(@sparm);
  601.                 spResult := SparmAddr;
  602.                 for i := 9 to 15 do
  603.                     begin
  604.                         spSlot := i;
  605.                         err := sReadPRAMRec(@SlotBlock);
  606.                         if sparm.BoardID = id then
  607.                             begin
  608.                                 GetSlotBase := bor($F0000000, spSlot * $100000 + spSlot * $1000000);
  609.                 superSlotBase := spSlot * $10000000;
  610.                                 exit(GetSlotBase)
  611.                             end;
  612.                     end;
  613.                 GetSlotBase := 0;
  614.             end;
  615.     end;
  616.  
  617.  
  618.     procedure SetupFGPort;
  619. {So we can use CopyBits, this routine sets up a color graf port that}
  620. {uses the memory on the frame grabber board as the PixMap.}
  621.         const
  622.             baseAddr32 = 4;
  623.         var
  624.             tPort: GrafPtr;
  625.             trect: rect;
  626.             SaveGDevice: GDHandle;
  627.     begin
  628.         SaveGDevice := GetGDevice;
  629.         SetGDevice(osGDevice);
  630.         GetPort(tPort);
  631.         fgPort := CGrafPtr(NewPtr(SizeOf(CGrafPort)));
  632.         OpenCPort(fgPort);
  633.         SetRect(trect, 0, 0, fgWidth, fgHeight);
  634.         with fgPort^ do
  635.             begin
  636.                 with PortPixMap^^ do
  637.                     begin
  638.                         BaseAddr := ptr(fgSlotBase);
  639.                         bounds := trect;
  640.                         RowBytes := BitOr(fgRowBytes, $8000);
  641.                         pmVersion := baseAddr32; {Needed for 8*24 GC card. See TN 275.}
  642.                     end;
  643.                 PortRect := trect;
  644.                 RectRgn(visRgn, trect);
  645.             end;
  646.         hlock(handle(fgPort^.PortPixMap));
  647.         fgPixMap := fgPort^.PortPixMap;
  648.         SetPort(tPort);
  649.         SetPalette(WindowPtr(fgPort), ExplicitPalette, false);
  650.         SetGDevice(SaveGDevice);
  651.     end;
  652.  
  653.  
  654.     function is50HzLG3: boolean;
  655.         const
  656.             BoardResourceID = 1;
  657.             VendorInfoID = 36;
  658.             PartNumberID = 4;
  659.             PartNumber50Hz = 'LG-3 50Hz';
  660.         var
  661.             SlotBlock: SpBlock;
  662.             err: OSErr;
  663.             PartNumberPtr: StringPtr;
  664.     begin
  665.         is50HzLG3 := false;
  666.         SlotBlock.spSlot := byte(bsr(band(fgSlotBase, $0f000000), 24));
  667.         SlotBlock.spId := BoardResourceID;
  668.         SlotBlock.spExtDev := 0;
  669.         err := SRsrcInfo(@SlotBlock);
  670.         if err <> 0 then
  671.             exit(is50HzLG3);
  672.         SlotBlock.spId := VendorInfoID;
  673.         err := SFindStruct(@SlotBlock);
  674.         if err <> 0 then
  675.             exit(is50HzLG3);
  676.         SlotBlock.spID := PartNumberID;
  677.         err := SGetCString(@SlotBlock);
  678.         if err <> 0 then
  679.             exit(is50HzLG3);
  680.         PartNumberPtr := C2PStr(SlotBlock.spResult);
  681.         if PartNumberPtr^ = PartNumber50Hz then
  682.             is50HzLG3 := true;
  683.         DisposePtr(Ptr(SlotBlock.spResult)); {need to free memory allocated by SGetCString()}
  684.     end;
  685.  
  686.  
  687.     function is50HzAG5: boolean;
  688.         const
  689.             BoardResourceID = 1;
  690.             VendorInfoID = 36;
  691.             PartNumberID = 4;
  692.             PartNumber50Hz = 'AG-5 50Hz';
  693.         var
  694.             SlotBlock: SpBlock;
  695.             err: OSErr;
  696.             PartNumberPtr: StringPtr;
  697.     begin
  698.         is50HzAG5 := false;
  699.         SlotBlock.spSlot := byte(bsr(band(fgSlotBase, $0f000000), 24));
  700.         SlotBlock.spId := BoardResourceID;
  701.         SlotBlock.spExtDev := 0;
  702.         err := SRsrcInfo(@SlotBlock);
  703.         if err <> 0 then
  704.             exit(is50HzAG5);
  705.         SlotBlock.spId := VendorInfoID;
  706.         err := SFindStruct(@SlotBlock);
  707.         if err <> 0 then
  708.             exit(is50HzAG5);
  709.         SlotBlock.spID := PartNumberID;
  710.         err := SGetCString(@SlotBlock);
  711.         if err <> 0 then
  712.             exit(is50HzAG5);
  713.         PartNumberPtr := C2PStr(SlotBlock.spResult);
  714.         if PartNumberPtr^ = PartNumber50Hz then
  715.             is50HzAG5 := true;
  716.         DisposePtr(Ptr(SlotBlock.spResult));  {need to free memory allocated by SGetCString()}
  717.     end;
  718.  
  719.  
  720.     function is50HzVG5: boolean;
  721.         const
  722.             BoardResourceID = 1;
  723.             VendorInfoID = 36;
  724.             PartNumberID = 4;
  725.             PartNumber50Hz = 'VG-5 50Hz';
  726.         var
  727.             SlotBlock: SpBlock;
  728.             err: OSErr;
  729.             PartNumberPtr: StringPtr;
  730.     begin
  731.         is50HzVG5 := false;
  732.         SlotBlock.spSlot := byte(bsr(band(fgSlotBase, $0f000000), 24));
  733.         SlotBlock.spId := BoardResourceID;
  734.         SlotBlock.spExtDev := 0;
  735.         err := SRsrcInfo(@SlotBlock);
  736.         if err <> 0 then
  737.             exit(is50HzVG5);
  738.         SlotBlock.spId := VendorInfoID;
  739.         err := SFindStruct(@SlotBlock);
  740.         if err <> 0 then
  741.             exit(is50HzVG5);
  742.         SlotBlock.spID := PartNumberID;
  743.         err := SGetCString(@SlotBlock);
  744.         if err <> 0 then
  745.             exit(is50HzVG5);
  746.         PartNumberPtr := C2PStr(SlotBlock.spResult);
  747.         if PartNumberPtr^ = PartNumber50Hz then
  748.             is50HzVG5 := true;
  749.         DisposePtr(Ptr(SlotBlock.spResult)); {need to free memory allocated by SGetCString()}
  750.     end;
  751.  
  752.  
  753.  procedure CheckLG3Buffer;
  754.   type
  755.    LongintPtr = ^Longint;
  756.   const
  757.    Pattern = $A596A596;
  758.   var
  759.    BufferPtr: LongintPtr;
  760.    mode: signedbyte;
  761.    
  762.    procedure SwapMode;
  763.    begin
  764.       {$ifc not PowerPC}
  765.       SwapMMUMode(mode);
  766.       {$endc}
  767.    end;
  768.    
  769.  begin
  770.   mode := true32b;
  771.   SwapMode;
  772.   BufferPtr := LongintPtr(fgSlotBase);
  773.   BufferPtr^ := Pattern;
  774.   BufferPtr := LongintPtr(bsl(band(fgSlotBase, $0f000000), 4) + (524288 * 2));
  775.   if BufferPtr^ = Pattern then begin
  776.     MaxLG3Frames := 2;
  777.       SwapMode;
  778.     exit(CheckLG3Buffer);
  779.    end;
  780.   BufferPtr := LongintPtr(bsl(band(fgSlotBase, $0f000000), 4) + (524288 * 8));
  781.   if BufferPtr^ = Pattern then begin
  782.     MaxLG3Frames := 8;
  783.       SwapMode;
  784.     exit(CheckLG3Buffer);
  785.    end;
  786.   BufferPtr := LongintPtr(bsl(band(fgSlotBase, $0f000000), 4) + (524288 * 32));
  787.   if BufferPtr^ = Pattern then begin
  788.     MaxLG3Frames := 32;
  789.       SwapMode;
  790.     exit(CheckLG3Buffer);
  791.    end
  792.   else begin
  793.     MaxLG3Frames := 128;
  794.       SwapMode;
  795.    end;
  796.  end;
  797.  
  798.  
  799.     procedure LookForFrameGrabbers;
  800.         const
  801.             ControlRegOffset = $80000;
  802.             ChannelRegOffset = $80004;
  803.             LG3ControlRegOffset = $C0000;
  804.             LG3ChannelRegOffset = $C0008;
  805.             AG5ControlRegOffset = $C0000;
  806.             AG5ChannelRegOffset = $C0008;
  807.             VG5ControlRegOffset = $C0000;
  808.             VG5ChannelRegOffset = $C0008;
  809.             BufferRegOffset = $C0004;
  810.             DacHighRegOffset = $C000C;
  811.             DacLowRegOffset = $C0010;
  812.             DacARegOffset = $C0014;
  813.             DacBRegOffset = $C0018;
  814.             ConstantRegOffset = $C0004;
  815.             ScaleHighRegOffset = $D0000;
  816.             ScaleLowRegOffset = $D0004;
  817.             DT2255id = $11A;
  818.             ScionLG3id = $48B;
  819.             ScionAG5id = $620;
  820.             ScionVG5id = $67E;
  821.             PalBufferSize = 393216; {768 x 512}
  822.         var
  823.             err: OSErr;
  824.             tPort: GrafPtr;
  825.             OptionKeyIsDown: boolean;
  826.     begin
  827.         FrameGrabber := NoFrameGrabber;
  828.         fgPixMap := nil;
  829.         if ShiftKeyDown then
  830.             exit(LookForFrameGrabbers);
  831.         OptionKeyIsDown := OptionKeyDown;
  832.         fgPort := nil;
  833.         fgSlotBase := GetSlotBase(ScionLG3id);
  834.         fgRowBytes := 1024;
  835.         if (fgSlotBase <> 0) and not OptionKeyIsDown then begin
  836.                 FrameGrabber := ScionLG3;
  837.                 ControlReg := ptr(fgSlotBase + LG3ControlRegOffset);
  838.                 ChannelReg := ptr(fgSlotBase + LG3ChannelRegOffset);
  839.                 BufferReg := ptr(fgSlotBase + BufferRegOffset);
  840.                 DacHighReg := ptr(fgSlotBase + DacHighRegOffset);
  841.                 DacLowReg := ptr(fgSlotBase + DacLowRegOffset);
  842.                 DacAReg := ptr(fgSlotBase + DacARegOffset);
  843.                 DacBReg := ptr(fgSlotBase + DacBRegOffset);
  844.                 fgWidth := 640;
  845.                 fgHeight := 480;
  846.                 if is50HzLG3 then begin
  847.                         fgWidth := 768;
  848.                         fgHeight := 512;
  849.                         if BufferSize < PalBufferSize then
  850.                             BufferSize := PalBufferSize;
  851.                     end;
  852.                 CheckLG3Buffer;
  853.                 SetupFGPort;
  854.                 DacLow := DefaultLG3DacLow;
  855.                 DacHigh := DefaultLG3DacHigh;
  856.                 ResetScionLG3;
  857.                 exit(LookForFrameGrabbers);
  858.             end;
  859.         fgSlotBase := GetSlotBase(ScionAG5id);
  860.         if (fgSlotBase <> 0) and not OptionKeyIsDown then begin
  861.                 FrameGrabber := ScionAG5;
  862.                 ControlReg := ptr(fgSlotBase + AG5ControlRegOffset);
  863.                 ChannelReg := ptr(fgSlotBase + AG5ChannelRegOffset);
  864.                 ConstantReg := ptr(fgSlotBase + ConstantRegOffset);
  865.                 DacHighReg := ptr(fgSlotBase + DacHighRegOffset);
  866.                 DacLowReg := ptr(fgSlotBase + DacLowRegOffset);
  867.                 ScaleHighReg := IntegerPtr(fgSlotBase + ScaleHighRegOffset);
  868.                 ScaleLowReg := IntegerPtr(fgSlotBase + ScaleLowRegOffset);
  869.                 fgWidth := 640;
  870.                 fgHeight := 480;
  871.                 if is50HzAG5 then begin
  872.                         fgWidth := 768;
  873.                         fgHeight := 512;
  874.                         if BufferSize < PalBufferSize then
  875.                             BufferSize := PalBufferSize;
  876.                     end;
  877.                 SetupFGPort;
  878.                 DacLow := DefaultAG5DacLow;
  879.                 DacHigh := DefaultAG5DacHigh;
  880.                 ResetScionAG5;
  881.                 exit(LookForFrameGrabbers);
  882.             end;
  883.         fgSlotBase := GetSlotBase(ScionVG5id);
  884.         if (fgSlotBase <> 0) and not OptionKeyIsDown then begin
  885.                 FrameGrabber := ScionVG5f;
  886.                 ControlReg := ptr(fgSlotBase + VG5ControlRegOffset);
  887.                 ChannelReg := ptr(fgSlotBase + VG5ChannelRegOffset);
  888.                 DacHighReg := ptr(fgSlotBase + DacHighRegOffset);
  889.                 DacLowReg := ptr(fgSlotBase + DacLowRegOffset);
  890.                 fgWidth := 640;
  891.                 fgHeight := 480;
  892.                 if is50HzVG5 then begin
  893.                         fgWidth := 768;
  894.                         fgHeight := 512;
  895.                         if BufferSize < PalBufferSize then
  896.                             BufferSize := PalBufferSize;
  897.                     end;
  898.                 SetupFGPort;
  899.                 DacLow := DefaultVG5DacLow;
  900.                 DacHigh := DefaultVG5DacHigh;
  901.                 ResetScionVG5f;
  902.                 exit(LookForFrameGrabbers);
  903.             end;
  904.         fgSlotBase := GetSlotBase(DT2255id);
  905.         if fgSlotBase <> 0 then begin
  906.                 FrameGrabber := QuickCapture;
  907.                 ControlReg := ptr(fgSlotBase + ControlRegOffset);
  908.                 ChannelReg := ptr(fgSlotBase + ControlRegOffset + 4);
  909.                 fgWidth := 640;
  910.                 fgHeight := 480;
  911.                 if band(ChannelReg^, 8) = 8 then begin {Check for 50Hz(PAL) card}
  912.                         fgWidth := 768;
  913.                         fgHeight := 512;
  914.                         if BufferSize < PalBufferSize then
  915.                             BufferSize := PalBufferSize;
  916.                     end;
  917.                 SetupFGPort;
  918.                 ResetQuickCapture;
  919.                 exit(LookForFrameGrabbers);
  920.             end;
  921.     end; {LookForFrameGrabbers}
  922.  
  923.  
  924.     procedure CheckBits;
  925.         const
  926.             QD32Trap = $AB03;
  927.             UnimplementedTrap = $A89F;
  928.         var
  929.             MainDevice: GDHandle;
  930.             myEnvRec: SysEnvRec;
  931.             err: OSErr;
  932.     begin
  933.         err := SysEnvirons(1, myEnvRec);
  934.         if err <> envNotPresent then
  935.             with MyEnvRec do
  936.                 begin
  937.                     if not HasColorQD then
  938.                         begin
  939.                             PutError('Sorry, NIH Image requires a Macintosh with Color QuickDraw.');
  940.                             ExitToShell;
  941.                         end;
  942.                     if not HasFPU and UsingFPU then
  943.                         begin
  944.                             PutError('Use the NonFPU version of NIH Image on Macs without a floating-point coprocessor.');
  945.                             ExitToShell;
  946.                         end;
  947.                     OldSystem := systemVersion < $0605;
  948.                     System7 := systemVersion >= $0700;
  949.                     if not System7 then
  950.                         begin
  951.                             PutError('System 7 required.');
  952.                             if not OptionKeyDown then
  953.                                 ExitToShell;
  954.                         end;
  955.                     SystemRefnum := sysVRefNum;
  956.                 end;
  957.         Has32BitQuickDraw := nGetTrapAddress(QD32Trap, ToolTrap) <> nGetTrapAddress(UnimplementedTrap, ToolTrap);
  958.         MainDevice := GetMainDevice;
  959.         ScreenPixMap := MainDevice^^.gdPMap;
  960.         ScreenRowBytes := BitAnd(ScreenPixMap^^.rowBytes, $1fff);
  961.         ScreenBase := ScreenPixMap^^.baseAddr;
  962.         FindMonitors(ScreenPixMap^^.PixelSize);
  963.     end;
  964.  
  965.  
  966.     procedure SetupMenus;
  967.         var
  968.             i: integer;
  969.     begin
  970.         AppleMenuH := GetMenu(AppleMenu);
  971.         InsertMenu(AppleMenuH, 0);
  972.         FileMenuH := GetMenu(FileMenu);
  973.         InsertMenu(FileMenuH, 0);
  974.         EditMenuH := GetMenu(EditMenu);
  975.         InsertMenu(EditMenuH, 0);
  976.         OptionsMenuH := GetMenu(OptionsMenu);
  977.         InsertMenu(OptionsMenuH, 0);
  978.         ProcessMenuH := GetMenu(ProcessMenu);
  979.         InsertMenu(ProcessMenuH, 0);
  980.         AnalyzemenuH := GetMenu(AnalyzeMenu);
  981.         InsertMenu(AnalyzemenuH, 0);
  982.         SpecialMenuH := GetMenu(SpecialMenu);
  983.         InsertMenu(SpecialMenuH, 0);
  984.         StacksMenuH := GetMenu(StacksMenu);
  985.         InsertMenu(StacksMenuH, 0);
  986.         WindowsMenuH := GetMenu(WindowsMenu);
  987.         InsertMenu(WindowsMenuH, 0);
  988.  
  989.         FontMenuH := GetMenu(FontMenu);
  990.         InsertMenu(FontMenuH, -1);
  991.         SizeMenuH := GetMenu(SizeMenu);
  992.         InsertMenu(SizeMenuH, -1);
  993.         StyleMenuH := GetMenu(StyleMenu);
  994.         InsertMenu(StyleMenuH, -1);
  995.         BinaryMenuH := GetMenu(BinaryMenu);
  996.         InsertMenu(BinaryMenuH, -1);
  997.         ArithmeticMenuH := GetMenu(ArithmeticMenu);
  998.         InsertMenu(ArithmeticMenuH, -1);
  999.         fftMenuH := GetMenu(fftMenu);
  1000.         InsertMenu(fftMenuH, -1);
  1001.         BackgroundMenuH := GetMenu(BackgroundMenu);
  1002.         InsertMenu(BackgroundMenuH, -1);
  1003.         PropagateMenuH := GetMenu(PropagateMenu);
  1004.         InsertMenu(PropagateMenuH, -1);
  1005.         ColorTablesMenuH := GetMenu(ColorTablesMenu);
  1006.         InsertMenu(ColorTablesMenuH, -1);
  1007.         AcquireMenuH := GetMenu(AcquireMenu);
  1008.         InsertMenu(AcquireMenuH, -1);
  1009.         ExportMenuH := GetMenu(ExportMenu);
  1010.         InsertMenu(ExportMenuH, -1);
  1011.         FilterMenuH := GetMenu(FilterMenu);
  1012.         InsertMenu(FilterMenuH, -1);
  1013.  
  1014.         TransferModeMenuH := GetMenu(TransferModeMenu);
  1015.         InsertMenu(TransferModeMenuH, -1);
  1016.  
  1017.         LineToolMenuH := GetMenu(LineToolMenu);
  1018.         InsertMenu(LineToolMenuH, -1);
  1019.  
  1020.         ImageMathOpsMenuH := GetMenu(ImageMathOpsMenu);
  1021.         InsertMenu(ImageMathOpsMenuH, -1);
  1022.  
  1023.         ImageListMenuH := GetMenu(ImageListMenu);
  1024.         InsertMenu(ImageListMenuH, -1);
  1025.  
  1026.         UnitsMenuH := GetMenu(UnitsMenu);
  1027.         InsertMenu(UnitsMenuH, -1);
  1028.  
  1029.         DrawMenuBar;
  1030.         AppendResMenu(AppleMenuH, 'DRVR');
  1031.         AppendResMenu(FontMenuH, 'FONT');
  1032.         NumFontItems := CountMItems(FontMenuH);
  1033.     end;
  1034.  
  1035.  
  1036.     function GetFolderDirID (parentFolderVRefNum: Integer; parentFolderDirID: LongInt; folderName: Str63; var folderDirID: LongInt): OSErr;
  1037.   {Given a folder's name, vRefNum, and parent dirID, find its dirID }
  1038.         var
  1039.             myCInfoPBRec: CInfoPBRec;
  1040.             retCode: OSErr;
  1041.     begin
  1042.         myCInfoPBRec.ioCompletion := nil;
  1043.         myCInfoPBRec.ioNamePtr := @folderName;
  1044.         myCinfoPBRec.ioVRefNum := parentFolderVRefNum;
  1045.         myCInfoPBRec.ioFDirIndex := 0; { use name, vRefNum, dirID }
  1046.         myCInfoPBRec.ioDrDirID := parentFolderDirID; { will be changed }
  1047.         retCode := PBGetCatInfoSync(@myCInfoPBRec); { IM IV-155 }
  1048.         if retCode = noErr then
  1049.             folderDirID := myCInfoPBRec.ioDrDirID;
  1050.         GetFolderDirID := retCode;
  1051.     end;
  1052.  
  1053.  
  1054.     procedure MyAppendMenu (menu: MenuHandle; item: integer; str: str255);
  1055.     begin
  1056.         AppendMenu(menu, ' ');
  1057.         SetMenuItemText(menu, item, str);
  1058.     end;
  1059.  
  1060.  
  1061.     procedure FindPlugIns;
  1062.         var
  1063.             err: OSErr;
  1064.             wdRefNum, index, SystemVRefNum: integer;
  1065.             name: Str255;
  1066.             ftype: OSType;
  1067.             PB: CInfoPBRec;
  1068.             ProcID, SystemDirID: LongInt;
  1069.             spec: FSSpec;
  1070.             pb2: WDPBRec;
  1071.             rCount, iFileRef: integer;
  1072.     begin
  1073.         if not System7 then
  1074.             exit(FindPlugIns);
  1075.         err := GetFolderDirID(LaunchVRefNum, LaunchDirID, 'Plug-Ins', PlugInsDirID);
  1076.         if err = NoErr then
  1077.             PlugInsVRefNum := LaunchVRefNum
  1078.         else if GetWDInfo(SystemRefNum, SystemVRefNum, SystemDirID, ProcID) = NoErr then
  1079.             if GetFolderDirID(SystemVRefNum, SystemDirID, 'Plug-Ins', PlugInsDirID) = NoErr then
  1080.                 PlugInsVRefNum := SystemVRefNum
  1081.             else
  1082.                 exit(FindPlugIns);
  1083.         err := OpenWD(PlugInsVRefNum, PlugInsDirID, 0, wdRefNum);
  1084.         if err <> NoErr then
  1085.             exit(FindPlugIns);
  1086.         index := 0;
  1087.         while true do
  1088.             begin
  1089.                 index := index + 1;
  1090.                 with PB do
  1091.                     begin
  1092.                         ioCompletion := nil;
  1093.                         ioNamePtr := @name;
  1094.                         ioVRefNum := wdRefNum;
  1095.                         ioDirID:=PlugInsDirID;
  1096.                         ioFDirIndex := index;
  1097.                         err := PBGetCatInfoSync(@PB); {ppc-bug}
  1098.                         if err = fnfErr then
  1099.                             leave;
  1100.                     end;
  1101.                 spec.vrefnum := PluginsVRefNum;
  1102.                 spec.parID := PlugInsDirID;
  1103.                 spec.name := name;
  1104.                 iFileRef := FSpOpenResFile(spec, fsCurPerm);
  1105.                 if iFileRef <> -1 then
  1106.                     begin
  1107.                         UseResFile(iFileRef);
  1108.                         rCount := Count1Resources('8BAM');
  1109.                         if rCount > 0 then
  1110.                             begin
  1111.                                 nAcqPlugIns := nAcqPlugIns + 1;
  1112.                                 if nAcqPlugIns = 1 then
  1113.                                     SetMenuItemText(AcquireMenuH, 1, name)
  1114.                                 else
  1115.                                     MyAppendMenu(AcquireMenuH, nAcqPlugIns, name);
  1116.                             end;
  1117.                         rCount := Count1Resources('8BEM');
  1118.                         if rCount > 0 then
  1119.                             begin
  1120.                                 nExportPlugIns := nExportPlugIns + 1;
  1121.                                 if nExportPlugIns = 1 then
  1122.                                     SetMenuItemText(ExportMenuH, 1, name)
  1123.                                 else
  1124.                                     MyAppendMenu(ExportMenuH, nExportPlugIns, name);
  1125.                             end;
  1126.                         rCount := Count1Resources('8BFM');
  1127.                         if rCount > 0 then
  1128.                             begin
  1129.                                 nFilterPlugIns := nFilterPlugIns + 1;
  1130.                                 if nFilterPlugIns = 1 then
  1131.                                     SetMenuItemText(FilterMenuH, 1, name)
  1132.                                 else
  1133.                                     MyAppendMenu(FilterMenuH, nFilterPlugIns, name);
  1134.                             end;
  1135.                         CloseResFile(iFileRef);
  1136.                     end;
  1137.                 ShowAnimatedWatch;
  1138.             end; {while}
  1139.         err := CloseWD(wdRefNum);
  1140.     end;
  1141.  
  1142.  
  1143.     procedure MakeGDevice;
  1144.   {Sets up an offscreen 8-bit graphics environment for use when the screen is not 8-bits.}
  1145.         var
  1146.             DeviceRect: Rect;
  1147.             h: CTabHandle;
  1148.             SaveDevice: GDHandle;
  1149.  
  1150.         procedure Abort;
  1151.         begin
  1152.             PutError('Error creating GDevice.');
  1153.             ExitToShell;
  1154.         end;
  1155.  
  1156.     begin
  1157.         SaveDevice := GetGDevice;
  1158.         SetRect(DeviceRect, 0, 0, 64, 64);
  1159.         h := GetCTable(AppleDefaultClut);
  1160.         if h = nil then
  1161.             abort;
  1162.         osGDevice := NewGDevice(0, -1);
  1163.         if osGDevice = nil then
  1164.             abort;
  1165.         with osGDevice^^ do
  1166.             begin
  1167.                 gdId := 0;
  1168.                 gdType := clutType;
  1169.                 gdResPref := 3;                                            { Color matching resolution. }
  1170.                 gdSearchProc := nil;
  1171.                 gdCompProc := nil;
  1172.                 gdFlags := $C401;                                            { 1100 0100 0000 0001 }
  1173.                 gdRect := DeviceRect;
  1174.                 with gdPMap^^ do
  1175.                     begin
  1176.                         baseAddr := nil;
  1177.                         bounds := DeviceRect;
  1178.                         rowBytes := 64 + $8000;
  1179.                         pixelSize := 8;
  1180.                         cmpCount := 1;
  1181.                         cmpSize := 8;
  1182.                         DisposeCTable(pmTable);
  1183.                         pmTable := h;
  1184.                     end;
  1185.             end;
  1186.         SetGDevice(SaveDevice);
  1187.     end;
  1188.  
  1189.  
  1190.     procedure Init;
  1191.         var
  1192.             i: integer;
  1193.             p: SyspPtr;
  1194.             mbhp: ^integer;
  1195.             str: str255;
  1196.             err: OSErr;
  1197.     begin
  1198.         SetApplLimit(ptr(LongInt(GetApplLimit) - StackSize));
  1199.         MaxApplZone;
  1200.         InitGraf(@qd.thePort);
  1201.         InitFonts;
  1202.         InitWindows;
  1203.         InitCursor;
  1204.         TEInit;
  1205.         InitDialogs(@SysResume);
  1206.         CheckBits;
  1207.         ScreenPort := GrafPtr(NewPtr(SizeOf(GrafPort)));
  1208.         OpenPort(ScreenPort);
  1209.         NoInfo := @NoInfoRec;
  1210.         Info := NoInfo;
  1211.         InfoWindow := nil;
  1212.         with BlackRGB do
  1213.             begin
  1214.                 red := 0;
  1215.                 blue := 0;
  1216.                 green := 0;
  1217.             end;
  1218.         with WhiteRGB do
  1219.             begin
  1220.                 red := -1;
  1221.                 blue := -1;
  1222.                 green := -1;
  1223.             end;
  1224.         with NoInfo^ do
  1225.             begin
  1226.                 iVersion:=version;
  1227.                 nlines := 0;
  1228.                 PixelsPerLine := 0;
  1229.                 ImageSize := 0;
  1230.                 PixMapSize := 0;
  1231.                 PicBaseAddr := nil;
  1232.                 PicBaseHandle := nil;
  1233.                 osPort := nil;
  1234.                 RoiShowing := false;
  1235.                 RoiType := NoRoi;
  1236.                 RoiRect := SrcRect;
  1237.                 roiRgn := NewRgn;
  1238.                 title := 'NoInfo';
  1239.                 Magnification := 1.0;
  1240.                 PictureType := NullPicture;
  1241.                 wptr := nil;
  1242.                 Changes := false;
  1243.                 BytesPerRow := 0;
  1244.                 SetRect(SrcRect, 0, 0, 0, 0);
  1245.                 PicRect := SrcRect;
  1246.                 wrect := SrcRect;
  1247.                 initwrect := wrect;
  1248.                 savewrect := wrect;
  1249.                 SaveSrcRect := SrcRect;
  1250.                 SaveMagnification := magnification;
  1251.                 savehloc := 0;
  1252.                 savevloc := 0;
  1253.                 ScaleToFitWindow := false;
  1254.                 nColors := 256;
  1255.                 ColorStart := 0;
  1256.                 ColorEnd := 255;
  1257.                 SaveColorStart := 0;
  1258.                 SaveColorEnd := 255;
  1259.                 FillColor1 := BlackRGB;
  1260.                 FillColor2 := BlackRGB;
  1261.                 SaveFill1 := BlackRGB;
  1262.                 SaveFill2 := BlackRGB;
  1263.                 LUTMode := GrayScale;
  1264.                 ColorTable := CustomTable;
  1265.                 InvertedColorTable := false;
  1266.                 xUnit := 'pixel';
  1267.                 xScale := 0.0;
  1268.                 yScale := 0.0;
  1269.                 zScale := 1.0;
  1270.                 PixelAspectRatio := 1.0;
  1271.                 SpatiallyCalibrated := false;
  1272.                 UnitOfMeasure := '';
  1273.                 PicNum := 1;
  1274.                 PidNum := 0;
  1275.                 HeaderOffset := -1;
  1276.                 ImageDataOffset := -1;
  1277.                 ColorMapOffset := -1;
  1278.                 for i := 0 to 255 do
  1279.                     ctable[i].value := 0;
  1280.                 Fit := Uncalibrated;
  1281.                 ZeroClip := false;
  1282.                 nCoefficients := 0;
  1283.                 for i := 1 to 6 do
  1284.                     Coefficient[i] := 0.0;
  1285.                 BinaryPic := false;
  1286.                 WindowState := NormalWindow;
  1287.                 Revertable := false;
  1288.                 LX1 := -1.0;
  1289.                 LY1 := -1.0;
  1290.                 LX2 := -1.0;
  1291.                 LY2 := -1.0;
  1292.                 LAngle := 0.0;
  1293.                 IdentityFunction := false;
  1294.                 StackInfo := nil;
  1295.                 Thresholding := false;
  1296.                 fileVersion := 0;
  1297.                 vref := 0;
  1298.                 DataType := EightBits;
  1299.                 AbsoluteMin := 0;
  1300.                 AbsoluteMax := 0;
  1301.                 CurrentMin := 0;
  1302.                 CurrentMax := 0;
  1303.                 LittleEndian := false;
  1304.                 InvertedImage := false;
  1305.                 DataH := nil;
  1306.             end;
  1307.         ExplicitPalette := NewPalette(256, nil, pmExplicit, 0);
  1308.         CScreenPort := CGrafPtr(NewPtr(SizeOf(CGrafPort)));
  1309.         OpenCPort(CScreenPort);
  1310.         SetPalette(WindowPtr(CScreenPort), ExplicitPalette, false);
  1311.         finished := false;
  1312.         FlushEvents(EveryEvent, 0);
  1313.         for i := 1 to 10 do
  1314.             MoreMasters;
  1315.         mbhp := pointer(MBarHeight);
  1316.         MenuBarHeight := mbhp^;
  1317.         SetRect(trect, tleft, ttop, tleft + twidth, ttop + theight);
  1318.         ToolWindow := NewCWindow(nil, trect, 'Tools', true, NoGrowDocProc, nil, false, 0);
  1319.         SetPalette(ToolWindow, ExplicitPalette, false);
  1320.         WindowPeek(ToolWindow)^.WindowKind := ToolKind;
  1321.         BringToFront(ToolWindow);
  1322.         ScreenWidth := qd.ScreenBits.Bounds.right;
  1323.         ScreenHeight := qd.ScreenBits.Bounds.bottom;
  1324.         SliceStart := 100;
  1325.         SliceEnd := 150;
  1326.         with SliceColor do
  1327.             begin
  1328.                 red := -1;
  1329.                 green := 0;
  1330.                 blue := 0;
  1331.             end;
  1332.         DensitySlicing := false;
  1333.         nExtraColors := 0;
  1334.         GrayMapReady := false;
  1335.         MakeGDevice;
  1336.         ResetGrayMap;   {LUT must be setup before InitMenus}
  1337.         InitMenus;
  1338.         SetRect(gmrect, gmleft, gmtop, gmleft + gmwidth, gmtop + gmheight);
  1339.         SetRect(gmSlide1, gmrectleft, gmrectbottom + gmSlide1Offset, gmrectleft + gmSlideWidth, gmrectbottom + gmSlide1Offset + gmSlideHeight);
  1340.         gmSlide1i := gmSlide1;
  1341.         InsetRect(gmSlide1i, 1, 1);
  1342.         SetRect(gmSlide2, gmrectleft, gmrectbottom + gmSlide2Offset, gmrectleft + gmSlideWidth, gmrectbottom + gmSlide2Offset + gmSlideHeight);
  1343.         gmSlide2i := gmSlide2;
  1344.         InsetRect(gmSlide2i, 1, 1);
  1345.         SetRect(gmIcon1, gmIcon1left, gmrectbottom + gmIconOffset, gmIcon1left + gmIconWidth, gmrectbottom + gmIconOffset + gmIconHeight);
  1346.         SetRect(gmIcon2, gmIcon2left, gmrectbottom + gmIconOffset, gmIcon2left + gmIconWidth, gmrectbottom + gmIconOffset + gmIconHeight);
  1347.         MapWindow := NewWindow(nil, gmrect, 'Map', true, NoGrowDocProc, nil, false, 0);
  1348.         WindowPeek(MapWindow)^.WindowKind := MapKind;
  1349.         SetRect(MapRect1, gmRectLeft, gmRectTop, gmRectRight, gmRectBottom);
  1350.         MapRect2 := MapRect1;
  1351.         InsetRect(MapRect2, -2, -2);
  1352.         cheight := 256 + (2 + nExtraColors) * ExtraColorsHeight;
  1353.         SetRect(crect, cleft, ctop, cleft + cwidth, ctop + cheight);
  1354.         LUTWindow := NewCWindow(nil, crect, 'LUT', true, NoGrowDocProc, nil, false, 0);
  1355.         SetPalette(LUTWindow, ExplicitPalette, false);
  1356.         WindowPeek(LUTWindow)^.WindowKind := LUTKind;
  1357.         rleft := 2;
  1358.         if ScreenHeight > 480 then
  1359.             rtop := ScreenHeight - rheight - 5
  1360.         else
  1361.             rtop := 358;
  1362.         SetRect(trect, rleft, rtop, rleft + rwidth, rtop + rheight);
  1363.         InfoWindow := NewWindow(nil, trect, 'Info', true, NoGrowDocProc, nil, false, 0);
  1364.         BringToFront(InfoWindow);
  1365.         WindowPeek(InfoWindow)^.WindowKind := InfoKind;
  1366.         BuggyWatch := GetCursor(WatchCursor);
  1367.         InitTools;
  1368.         MakeCursors;
  1369.         nPics := 0;
  1370.         nextPid := -1;
  1371.         HistoWindow := nil;
  1372.         PlotWindow := nil;
  1373.         IsInsertionPoint := false;
  1374.         MaskRgn := NewRgn;
  1375.         PlotPICT := nil;
  1376.         AutoscalePlots := true;
  1377.         InvertPlots := false;
  1378.         LinePlot := true;
  1379.         DrawPlotLabels := true;
  1380.         FixedSizePlot := false;
  1381.         ProfilePlotMin := 0;
  1382.         ProfilePlotMax := 255;
  1383.         ProfilePlotWidth := 300;
  1384.         ProfilePlotHeight := 150;
  1385.         SprayCanDiameter := 32;
  1386.         SprayCanRadius := 16;
  1387.         SprayCanRadius2 := 256;
  1388.         BrushWidth := 14;
  1389.         BrushHeight := 14;
  1390.         CurrentUndoSize := 0;
  1391.         p := GetSyspPtr;
  1392.         BlinkTime := BitAnd($000F, p^.volclik) * 4;
  1393.         MakePatterns;
  1394.         info^.LUTMode := GrayScale;
  1395.         PicLeftBase := twidth + cwidth + 10;
  1396.         PicTopBase := MenuBarHeight + 20;
  1397.         PicLeft := PicLeftBase;
  1398.         PicTop := PicTopBase;
  1399.         CurrentFontID := Helvetica;
  1400.         CurrentStyle := []; {plain}
  1401.         CurrentSize := 12;
  1402.         TextJust := teJustLeft;
  1403.         TextBack := NoBack;
  1404.         MouseState := NotInRoi;
  1405.         WhatsOnClip := NothingOnClip;
  1406.         InitExtraColors;
  1407.         OldScrapCount := GetScrapCount;
  1408.         ClipboardConverted := false;
  1409.         BufferSize := DefaultBufferSize;
  1410.         DacLow := DefaultLG3DacLow;
  1411.         DacHigh := DefaultLG3DacHigh;
  1412.         LookForFrameGrabbers;
  1413.         VideoChannel := 0;
  1414.         Digitizing := false;
  1415.         debugging := false;
  1416.         BlankFieldInfo := nil;
  1417.         InvertVideo := false;
  1418.         HighlightSaturatedPixels := false;
  1419.         PlotCount := 0;
  1420.         PlotAvg := 1;
  1421.         ActualPlotMin := 0.0;
  1422.         ActualPlotMax := 0.0;
  1423.         ClipTextInBuffer := false;
  1424.         TextBufP := TextBufPtr(NewPtr(SizeOf(TextBufType)));
  1425.         if TextBufP = nil then
  1426.             ExitToShell;
  1427.         MacrosP := MacrosPtr(NewPtr(SizeOf(MacrosRec)));
  1428.         if MacrosP = nil then
  1429.             ExitToShell;
  1430.         mCount := 0;
  1431.         mCount2 := 0;
  1432.         nPoints := 0;
  1433.         nLengths := 0;
  1434.         nAngles := 0;
  1435.         for i := 1 to MaxStandards do
  1436.             StandardValues[i] := BadReal;
  1437.         nStandards := 0;
  1438.         nKnownValues := 0;
  1439.         for i := 0 to 255 do
  1440.             cvalue[i] := i;
  1441.         WhatToUndo := NothingToUndo;
  1442.         WhatToCopy := NothingToCopy;
  1443.         PrintRecord := nil;
  1444.         printing := false;
  1445.         HalftoneFrequency := 53;
  1446.         HalftoneAngle := 45;
  1447.         HalftoneDotFunction := true;
  1448.         cr := chr(13);
  1449.         crStr:=chr(13);
  1450.         tab := chr(9);
  1451.         BackSpace := chr(8);
  1452.         eofChr := chr(4);
  1453.         measuring := false;
  1454.         measurements := [AreaM, MeanM];
  1455.         UpdateFitEllipse;
  1456.         nListColumns := 0;
  1457.         if FrameGrabber=ScionAG5 then begin
  1458.             FramesToAverage := 32;
  1459.             VideoRateAveraging:=true
  1460.         end else begin
  1461.             FramesToAverage := 16;
  1462.             VideoRateAveraging := false;
  1463.         end;
  1464.         NewPicWidth := 552;
  1465.         NewPicHeight := 436;
  1466.         RestoreUndoBuf := true;
  1467.         MaxScionWidth := 600;
  1468.         ThresholdToForeground := true;
  1469.         NonThresholdToBackground := true;
  1470.         SelectionMode := NewSelection;
  1471.         RoiMovementState := Unconstrained;
  1472.         PasteControl := nil;
  1473.         PasteTransferMode := SrcCopy;
  1474.         WhatToImport := ImportTIFF;
  1475.         ImportCustomWidth := 512;
  1476.         ImportCustomHeight := 512;
  1477.         ImportCustomSlices := 1;
  1478.         ImportCustomOffset := 0;
  1479.         ImportCustomDepth := EightBits;
  1480.         ImportSwapBytes := false;
  1481.         ImportCalibrate := true;
  1482.         ImportAll := false;
  1483.         ImportInvert := false;
  1484.         RoiNudged := false;
  1485.         ForegroundIndex := BlackIndex;
  1486.         BackgroundIndex := WhiteIndex;
  1487.         OpPending := false;
  1488.         RedoSelection := false;
  1489.         WandAutoMeasure := false;
  1490.         WandAdjustAreas := false;
  1491.         OptionKeyWasDown := false;
  1492.         BinaryIterations := 1;
  1493.         ScaleArithmetic := true;
  1494.         InfoMessage := '';
  1495.         SaveAsWhat := asTIFF;
  1496.         ExportAsWhat := asRaw;
  1497.         AnalyzingParticles := false;
  1498.         RedirectSampling := false;
  1499.         MinParticleSize := 1;
  1500.         MaxParticleSize := 999999;
  1501.         LabelParticles := true;
  1502.         OutlineParticles := false;
  1503.         IgnoreParticlesTouchingEdge := false;
  1504.         IncludeHoles := false;
  1505.         SaveAllState := NoSaveAll;
  1506.         InvertYCoordinates := true;
  1507.         ContinuousHistogram := false;
  1508.         DrawLabels(' ', '', '');
  1509.         HistogramSliceStart := 0;
  1510.         HistogramSliceEnd := 255;
  1511.         RoiUpdateTime := 0;
  1512.         FieldWidth := 9;
  1513.         precision := 2;
  1514.         MeasurementToRedo := 0;
  1515.         nMacros := 0;
  1516.         macro := false;
  1517.         KernelsRefNum := 0;
  1518.         DefaultRefNum := 0;
  1519.         MacrosRefNum := 0;
  1520.         LaunchVRefNum := 0;
  1521.         LaunchDirID := 0;
  1522.         PlugInsVRefNum := 0;
  1523.         PlugInsDirID := 0;
  1524.         DefaultFileName := '';
  1525.         rsHScale := 1.0;
  1526.         rsVScale := 1.0;
  1527.         rsAngle := 0.0;
  1528.         rsMethod := NearestNeighbor;
  1529.         rsCreateNewWindow := true;
  1530.         rsInteractive := false;
  1531.         ImportAutoScale := true;
  1532.         ImportMin := 0.0;
  1533.         ImportMax := 255.0;
  1534.         InvertPixelValues := false;
  1535.         OscillatingMovies := false;
  1536.         DriverHalftoning := true;
  1537.         LivePasteMode := false;
  1538.         ShowCount := true;
  1539.         PasteControlLeft := ScreenWidth - pcwidth - 10;
  1540.         PasteControlTop := trunc(ScreenHeight * 0.2);
  1541.         MaxMeasurements := 256;
  1542.         MaxCoordinates := 10000;
  1543.         ResultsLeft := PicLeftBase;
  1544.         ResultsTop := 56;
  1545.         UnsavedResults := false;
  1546.         MajorLabel := 'Major';
  1547.         MinorLabel := 'Minor';
  1548.         User1Label := 'User 1';
  1549.         User2Label := 'User 2';
  1550.         ShowHeadings := false;
  1551.         MakingLOI := false;
  1552.         LOIType := Straight;
  1553.         MakingStack := false;
  1554.         FramesWanted := 20;
  1555.         ScaleConvolutions := true;
  1556.         FasterBackgroundSubtraction := true;
  1557.         BallRadius := 50;
  1558.         DelayTicks := 0;
  1559.         CmdPeriodToStop := 'Type cmd-''.'' to stop.';
  1560.         CommandKey := chr(17);
  1561.         BinaryCount := 4;
  1562.         BinaryThreshold := BinaryCount * 255;
  1563.         ClipboardColor := BlackRGB;
  1564.         InitAngle := 0;                                             {default is one full revolution of volume}
  1565.         TotalAngle := 360;
  1566.         AngleInc := 10;                                           {in ten-degree increments}
  1567.         TransparencyUpper := 254;                      {default has only value 255 transparent}
  1568.         TransparencyLower := 0;
  1569.         DepthCueSurf := 0;                                     {default has full depth-cueing for surface}
  1570.         DepthCueInt := 50;                                     {components and 50% depth-cueing elsewhere}
  1571.         Opacity := 0;
  1572.         SaveProjections := FALSE;                         {by default, do not save and close projections}
  1573.         AxisOfRotation := xAxis;
  1574.         MinProjSize := TRUE;                                {by default, make all windows just big enough}
  1575.         ProjectionMethod := NearestPoint;
  1576.         MeterWindow := nil;
  1577.         nCoordinates := 0;
  1578.         CoordinatesWidth := 0;
  1579.         CoordinatesHeight := 0;
  1580.         CoordinatesRoiType := NoRoi;
  1581.         SwitchLUTOnSuspend := false;
  1582.         SumFrames := false;
  1583.         ShowIntegratedValues := false;
  1584.         FixIntegrationScale := false;
  1585.         IntegrationMin := 0;
  1586.         IntegrationMax := 4096;
  1587.         ExternalTrigger := false;
  1588.         BlindMovieCapture := false;
  1589.         VideoControl := nil;
  1590.         SyncMode := NormalSync;
  1591.         DitherColor := true;
  1592.         RGBLut := CustomLUT;
  1593.         with Highlight1 do
  1594.             begin
  1595.                 red := -1;
  1596.                 green := 0;
  1597.                 blue := 0;
  1598.             end;
  1599.         with Highlight254 do
  1600.             begin
  1601.                 red := -1;
  1602.                 green := -1;
  1603.                 blue := 0;
  1604.             end;
  1605.         HighlightMode := false;
  1606.         LegalWithoutImage := [UpdateLutC, StartC, ShowResultsC, GetPicSizeC, PutMsgC, ExitC, CaptureC, MoveToC, BeepC, MakeNewC, SetPaletteC, SetBackC, GetRoiC, OpenC, ImportC, SetImportC, SetMinMaxC, SetCustomC, nPicsC, WaitC, SetSizeC, TriggerC, AverageFramesC, SaveStateC, RestoreStateC, SetCounterC, MakeStackC, ShowMsgC, SetUser1C, SetUser2C, SetOptionsC, RequiresC];
  1607.         LegalWithoutImage := LegalWithoutImage + [DisposeAllC, GetTimeC, SetForeC, SetBackC, GetStringC, OpenSerialC, GetSerialC, PutSerialC, SetCursorC, TickCountC, ConcatC, SetVideoC, StringToNumC, ChannelC, AcquireC, UndoSizeC, CallFilterC, PhotoModeC, DrawTextC, WriteC, WritelnC, NewTextWindowC, UserCodeC, SelectWindowC, BitAndC, BitOrC, WindowTitleC, ScaleConvolutionsC];
  1608.         LegalWithoutImage := LegalWithoutImage + [SaveC, SaveAsC, CloseC, DisposeC, PosC, DeleteC, LengthC, SetPrecisionC, SetExportC, ExportC, SetFontC, SetFontSizeC, SetTextC, GetC, MoveWindowC];
  1609.         TopOfStack := 0;
  1610.         SerialBufferP := nil;
  1611.         OpeningPlugInWindow := false;
  1612.         LG3DacA := 0;
  1613.         LG3DacB := 0;
  1614.         LG3DataOut := 0;
  1615.         nAcqPlugIns := 0;
  1616.         nExportPlugIns := 0;
  1617.         nFilterPlugIns := 0;
  1618.         LastAcqPlugIn := '';
  1619.         LastFilterPlugIn := '';
  1620.         LastExportPlugIn := '';
  1621.         TextInfo := nil;
  1622.         nTextWindows := 0;
  1623.         NewTitle := 'Untitled';
  1624.         CurrentWPtr := nil;
  1625.         CurrentKind := 0;
  1626.         SearchString := '';
  1627.         TextCreator := 'Imag';
  1628.         CurrentMathOp := SubMath;
  1629.         MathSrc1 := 1;
  1630.         MathSrc2 := 1;
  1631.         MathSubGain := 0.5;
  1632.         MathSubOffset := 128.0;
  1633.         MathGain := MathSubGain;
  1634.         MathOffset := MathSubOffset;
  1635.         MathResult := 'Result';
  1636.         APReset := true;
  1637.         ShowPlot := true;
  1638.         FiducialMethod := OnScreen;
  1639.         ConfirmFidClicks := false;
  1640.         WatchIndex := 1;
  1641.         WireframeSurfacePlots := true;
  1642.         GrayscaleSurfacePlots := false;
  1643.         RankFilter := MedianRank;
  1644.         RankIterations := 1;
  1645.         TextScrollActionProc:=nil;
  1646.         AboutBoxFilterProc:=nil;    
  1647.         AboutBoxUserProc:=nil;
  1648.         ResultsScrollActionProc:=nil;
  1649.         ImageMathUserProc:=nil;
  1650.         SetScaleUserProc:=nil;
  1651.         OpenDHookProc:=nil;
  1652.         SaveAsDHookProc:=nil;
  1653.         ImportDHookProc:=nil;
  1654.         ExportDHookProc:=nil;
  1655.         BitInfoProc:=nil;
  1656.         GetPictDataProc:=nil;
  1657.         TestAbortProc:=nil;
  1658.         UpdateProgressProc:=nil;
  1659.         AG5LutMode := false;
  1660.         AG5GrabMode := GrabNormal;
  1661.         AG5BufferMode := Read0Lut1Grab0;
  1662.         IntegrateOnChip:=false;
  1663.         OpeningFinderFiles:=false;
  1664.         gNumberSlices:=true;
  1665.         gBorders:=true;
  1666.         RealImageMath:=false;
  1667.         DicomInitialized := false;
  1668.         ImportingDicom := false;
  1669.         err := HGetVol(nil, StartupSpec.vRefNum, StartupSpec.parID);
  1670.         OpeningRGB := false;
  1671.         PrecisionTiming := false;
  1672.         LG3BufferCapture := false;
  1673.         TimeStamp := false;
  1674.         SecondsPerFrame := 0.0;
  1675.         TriggerFirstFrameOnly := true;
  1676.         UseExistingStack := false;
  1677.         RealArithmetic := false;
  1678.         vdig := nil;
  1679.         fgScale := 1;
  1680.         GWorldLUT := nil;
  1681.         osGWorld := nil;
  1682.         DigitizerMode := digitizeGrayscale;
  1683.         UseBuiltinDigitizer := true;
  1684.         DigitizerStandard:= defaultStd;
  1685. end;
  1686.  
  1687.  
  1688. end.